package com.example.administrator.maizuofilm.moviedetails;

import com.example.administrator.maizuofilm.moviedetails.bean.Comment;
import com.example.administrator.maizuofilm.moviedetails.bean.Details;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by hansen on 2016/7/12.
 */
public class MovieDetailsPresenter implements  MovieDetailsContract.MovieDetailsP {
private MovieDetailsContract.MovieDetailsM model;
    private MovieDetailsContract.MovieDetailsV view;
    public MovieDetailsPresenter(MovieDetailsContract.MovieDetailsM model,MovieDetailsContract.MovieDetailsV view){
        this.model=model;
        this.view=view;
        EventBus.getDefault().register(this);

    }


    @Override
    public void getData(String path) {
        model.getDate(path);
    }

    @Override
    public void getComment(String path) {
        model.getComment(path);
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void oncomm(Comment comm){
        if (comm==null){
            view.onCommentFail("错误");

        }else {
            view.onComment(comm);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void Sub(Details details){
        if (details==null){
            view.getFail("发送错误");
        }else {
            view.getData(details);
        }
    }
}
